<template>
  <transition
    :css="false"
    @enter='enter'
    @leave='leave'>
    <div class="mini-play" v-show="this.isMiniPlayer">
      <div class="player-wraper">
        <div class="player-left" @click="showNaormalPlayer">
          <img :src="this.currentSong.picUrl" alt="" ref="isPlaying">
          <div class="title">
            <h3>{{this.currentSong.name}}</h3>
            <p>{{this.currentSong.singer}}</p>
          </div>
        </div>
        <div class="player-right">
          <div class="play" @click.stop="play" ref="play"></div>
          <div class="list" @click.stop="showList"></div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import Velocity from 'velocity-animate'
import 'velocity-animate/velocity.ui'
export default {
  name: 'MiniPlayer',
  data () { return {} },
  computed: {
    ...mapGetters([
      'isMiniPlayer',
      'isPlaying',
      'currentSong'
    ])
  },
  methods: {
    ...mapActions([
      'setFullPlayer',
      'setMiniPlayer',
      'setPlaying'
    ]),
    showNaormalPlayer () {
      this.setFullPlayer(true)
      this.setMiniPlayer(false)
    },
    showList () {
      this.$emit('showList')
      this.setMiniPlayer(false)
    },
    play () {
      this.setPlaying(!this.isPlaying)
    },
    enter (el, done) {
      Velocity(el, 'transition.bounceUpIn', { duration: 1000, delay: 500 }, function () {
        done()
      })
    },
    leave (el, done) {
      Velocity(el, 'transition.bounceDownOut', { duration: 1000 }, function () {
        done()
      })
    }
  },
  watch: {
    isPlaying (newValue, oldValue) {
      if (newValue) {
        this.$refs.play.classList.add('active')
        this.$refs.isPlaying.classList.add('active')
      } else {
        this.$refs.play.classList.remove('active')
        this.$refs.isPlaying.classList.remove('active')
      }
    }
  }
}
</script>

<style scoped lang='scss'>
  @import '../../assets/css/variable.scss';
  @import '../../assets/css/mixin.scss';
  .mini-play{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 150px;
    .player-wraper{
      height: 150px;
      @include bg_color();
      display: flex;
      justify-content: space-between;
      align-items: center;
      .player-left{
        display: flex;
        padding: 0 0 0 30px;
        img{
          width: 100px;
          height: 100px;
          border-radius: 50%;
          margin: 0 20px 0 0;
          animation: sport 4s linear infinite;
          animation-play-state: paused;
          &.active{
            animation-play-state: running;
          }
        }
        .title{
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          h3{
             @include font_size($font_medium);
             @include font_color();
          }
          p{
             @include font_size($font_medium_s);
             @include font_color();
          }
        }
      }
      .player-right{
        display: flex;
        align-items: center;
        .play{
          width: 80px;
          height: 80px;
          @include bg_img('../../assets/images/play');
          &.active{
          @include bg_img('../../assets/images/pause');
        }
        }
        .list{
          width: 120px;
          height: 120px;
          @include bg_img('../../assets/images/list')
        }
      }
    }
  }
  @keyframes sport{
    from{
      transform: rotate(0deg);
    }
    to{
      transform: rotate(360deg)
    }
  }
</style>
